package finaldataanalysis;


/*
 * codice che serve per analisi statistica sugli utenti . In particolare per trovare il massimo/minimo
 *  numero di eventi, media, devstd..
 * 
 */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FinalMain {
	
	public static void main(String [] args) throws Exception{
	
		List<String> slist = new ArrayList<String>();
		
	    String filename = "C:\\Users\\Alket\\codeindigo\\FlickrAPI\\TO_bbox\\FlicrUsers3EventsTS2106-3107.csv";
		System.out.println(filename);
		List<FinalOb2> list = new ArrayList<FinalOb2>();
		int count = 0;
		BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
		Map<Integer, Integer>map = new HashMap<Integer, Integer>();
		Map<String, Integer>map2 = new HashMap<String, Integer>();
		String line = "";
		List<Integer> listint = new ArrayList<Integer>();
		List<String> str = new ArrayList<String>();
		while((line = br.readLine())!=null){
		   String[] linea = line.split(",");
	       String usr = linea[0];
		     str.add(usr); 
		 		}br.close();
		//System.out.println(count);
		//Collections.sort(integer);
		
		int cont = 1;
		for (int i = 1; i < str.size(); i++) {
			String j = str.get(i);
			String k = str.get(i-1);
			
			if(j.equals(k)){
				cont++;
			}
			else{
				map2.put(k, cont);
				cont = 1;
			}
		}
		for (String i : map2.keySet()) {
		 System.out.println(map2.get(i));
		}
	
		//Map<String, Integer>map = new HashMap<String, Integer>();
	
		
		/*for(int i = 1; i < list.size(); i++){
			
			String tu1 = list.get(i).usert;
			String tu2 = list.get(i-1).usert;
			
			if (tu1.equals(tu2)){
				count++;
			}
			else{
				map.put(tu2, count);
				count = 1;
			}
		}*/
		
		
		/*
		String filename = "C:\\Users\\Alket\\codeindigo\\FlickrAPI\\TO_bbox\\TwitterUsersFrequencyOfEvents.csv";
		BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
		String line ="";
		List<Integer> list = new ArrayList<Integer>();
		List<Integer> list2 = new ArrayList<Integer>();
		Map<String, Integer> slist2 = new HashMap<String, Integer>();
          while((line = br.readLine())!=null){
			String[] linea = line.split(", ");
	          
			  String us = linea[0];
        	  int k = Integer.parseInt(linea[1]);
	        
	        slist2.put(us,k);
	        
		   }br.close();
		   
		   for(String s: slist2.keySet()){
			   int i = slist2.get(s);
			   list2.add(i);
		   }
		  double media = 0;
		  media = mean(list2);
		  int max = findMax(list2);
			System.out.println(max);
			int min = findMin(list2);
			System.out.println(min);
		  System.out.println(media);
		  */
	     }
	
	
	public static double mean(List<Integer> meanlist)throws Exception{
		
		double mean = 0; 
		double somma = 0;
		for (int i = 0; i < meanlist.size(); i++) {
			somma = somma+meanlist.get(i);
			
		}
		int max = 0; 
		System.out.println(somma);
		mean = somma /17681;
		return mean;
		
	}
	
	public static int findMax(List<Integer>list){
		
		int max = 0;
		for (int i = 0; i < list.size(); i++) {
			int k = list.get(i);
			
			if(k > max){
				max = k;
			}
		}
		return max;
	}
public static int findMin(List<Integer>list){
		
		int min = 400;
		for (int i = 0; i < list.size(); i++) {
			int k = list.get(i);
			
			if(k < min){
				min = k;
			}
		}
		return min;
	}
	
}
